<?php
namespace backend\modules\guild\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\activeRecords\Guild;

/**
 * GuildSearch represents the model behind the search form of `app\models\activeRecords\Guild`.
 */
class GuildSearch extends Guild
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'guild_status', 'guild_bank', 'guild_game', 'add_time'], 'integer'],
            [['guild_name', 'guild_sign', 'guild_contact', 'guild_phone', 'guild_qq'], 'safe'],
            [['guild_divide', 'guild_deducted'], 'number'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Guild::find();

        // add conditions that should always apply here
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'guild_status' => $this->guild_status,
            'guild_bank' => $this->guild_bank,
            'guild_game' => $this->guild_game,
            'guild_divide' => $this->guild_divide,
            'guild_deducted' => $this->guild_deducted,
            'add_time' => $this->add_time,
        ]);

        $query->andFilterWhere(['like', 'guild_name', $this->guild_name])
            ->andFilterWhere(['like', 'guild_sign', $this->guild_sign])
            ->andFilterWhere(['like', 'guild_contact', $this->guild_contact])
            ->andFilterWhere(['like', 'guild_phone', $this->guild_phone])
            ->andFilterWhere(['like', 'guild_qq', $this->guild_qq]);

        return $dataProvider;
    }
}
